package com.business.components.dynamicrow.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.common.URL;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.common.StringProcess;

@Controller
@RequestMapping(value = "/components/row")
public class RowController {

	
	@RequestMapping({ "/show" })
	public String show(ModelMap model) {
		
		List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> item;
		
		item = new HashMap<String, Object>();
		item.put("index", "0");
		item.put("txt1", "a1");
		item.put("txt2", "a2");
		list.add(item);
		
		item = new HashMap<String, Object>();
		item.put("index", "1");
		item.put("txt1", "a3");
		item.put("txt2", "a4");
		list.add(item);
		
		item = new HashMap<String, Object>();
		item.put("index", "2");
		item.put("txt1", "a5");
		item.put("txt2", "a6");
		list.add(item);
		
		String rowData=JSON.toJSONString(list);
		rowData = StringProcess.encode(rowData);
		model.put("rowData1", rowData);
		
		return "components/row/show";
	}
	
	@RequestMapping(params = "method=save", method = RequestMethod.POST)
	public void save(HttpServletRequest request, HttpServletResponse response) {
		
		String rowResult = request.getParameter("hidDyRow1");
				
		if(rowResult.length()>0)
		{
			rowResult = StringProcess.decode(rowResult);
			List<Map<String,Object>> list = JSON.parseObject(rowResult, new TypeReference<List<Map<String,Object>>>(){});
			
			String a="";
		}
		
	}
}
